

#include "VolumeLimite.h"



Esfera::Esfera()
{


}


void Esfera::CrearEsferaCubo(Vertice *v1, Vertice *v2)
{
	float fPromX, fPromY, fPromZ;
	float fDistMax = -100.0;
	float fComodin = 0.0;

	fPromX = (float)(v1->getX()+v2->getX())/(float)(2.0);
	fPromY = (float)(v1->getY()+v2->getY())/(float)(2.0);
	fPromZ = (float)(v1->getZ()+v2->getZ())/(float)(2.0);

	objCentro.setX(fPromX);
	objCentro.setY(fPromY);
	objCentro.setZ(fPromZ);

	fComodin = CalcularDistancia(v1,v2);

	if(fComodin>fDistMax)
	{
		fDistMax = fComodin;	
	}

	fRadio = fDistMax/2.0;
}

void Esfera::CrearEsferaTriangulo(Triangulo t)
{
	float fPromX, fPromY, fPromZ;
	float fDistMax = -100.0;
	float fComodin = 0.0;

	fPromX = (float)(t.getVertice1()->getX()+t.getVertice2()->getX()+t.getVertice3()->getX())/(float)(3.0);
	fPromY = (float)(t.getVertice1()->getY()+t.getVertice2()->getY()+t.getVertice3()->getY())/(float)(3.0);
	fPromZ = (float)(t.getVertice1()->getZ()+t.getVertice2()->getZ()+t.getVertice3()->getZ())/(float)(3.0);

	objCentro.setX(fPromX);
	objCentro.setY(fPromY);
	objCentro.setZ(fPromZ);

	fComodin = CalcularDistancia(t.getVertice1(),objCentro);

	if(fComodin>fDistMax)
	{
		fDistMax = fComodin;	
	}
	
	fComodin = CalcularDistancia(t.getVertice2(),objCentro);

	if(fComodin>fDistMax)
	{
		fDistMax = fComodin;
	}

	fComodin = CalcularDistancia(t.getVertice3(),objCentro);

	if(fComodin>fDistMax)
	{
		fDistMax = fComodin;
	}

	fRadio = fDistMax/2.0;
}


bool TestEsfera_Esfera(Esfera e1, Esfera e2)
{
	float fDistancia = 0.0;

	fDistancia = CalcularDistancia(e1.get_Centro(),e2.get_Centro())/2.0;

	if(fDistancia<(e1.get_Radio()+e2.get_Radio()))
	{
		return true;
	}
	else
	{
		return false;
	}
}